package jeudelavie.modele;

import java.util.Observable;
import java.util.Observer;
import java.util.logging.Level;
import java.util.logging.Logger;


/**
 * Simulateur permet l'interopérablilité des traitement métier
 * @author epulapp
 */
public class Simulateur {
    
    private boolean isPlay;
    private Environnement simulable;
    private final Thread thread;
    
    /**
     * Constructeurs
     */
    
    public Simulateur(int hauteur, int largeur) {
        simulable = new Environnement(hauteur, largeur);
        thread = new Thread() {
            @Override
            public void run() {
                while (true) {
                    if (isPlay)
                        simulable.calculer();
                    try {
                        Thread.currentThread().sleep(100);
                    } catch (InterruptedException ex) {
                        Logger.getLogger(Environnement.class.getName()).log(Level.SEVERE, null, ex);
                    }
                }
            } // run()
        };//Thread
        thread.start();
        isPlay = true;
    }//Simulateur()
    
    /**
     * Fonctions public
     */
    
    public void play() {
        /*synchronized(thread) { 
            thread.notify();
        }*/
        isPlay = true;
    } // play()
    
    public void pause() {
        /*try {
            synchronized(thread) { 
                thread.wait();
            }
        } catch (InterruptedException ex) {
            Logger.getLogger(Simulateur.class.getName()).log(Level.SEVERE, null, ex);
        }*/
        isPlay = false;
    } // pause()

    public void run() {
    }
    
    /**
     * Getters / setters
     */

    public boolean isIsPlay() {
        return isPlay;
    }

    public void setIsPlay(boolean isPlay) {
        this.isPlay = isPlay;
    }

    public Simulable getSimulable() {
        return simulable;
    }

    public void setSimulable(Environnement simulable) {
        this.simulable = simulable;
    }

    
}//Simulateur
